package com.itguigu.glimail.order.rabbittest;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Slf4j
@RestController
public class RabbitTestController {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("/sendMs/{num}")
    public String sendMs(@PathVariable("num") int num) {
        for (int i = 0; i < num; i++) {
            UserIngo userIngo = new UserIngo();
            userIngo.setAge(10);
            userIngo.setName("啦啦");

            rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", userIngo,new CorrelationData(UUID.randomUUID().toString()));
            log.info("消息发送成功{}", userIngo);
        }
        return "ok";
    }
}
